﻿/// <reference path="jquery-1.8.0.min.js" />
/*
*followParent 1.2.2
*Copyright (c) 2009 AtHome
*Date:2012-10-26
*轻易设置设置jq对象相对于父容器的位置及大小（单位：px）
*/
(function ($) {
    $.fn.followParent32 = function (options) {
        /*{
        cutWidth:int//减去的宽度
        cutHeight:int//减去的高度
        left:int
        right:int
        top:int
        bottom:int
        center:bool
        middle:bool
        }*/
        var defaults = {}
        var options = $.extend({}, defaults, options);
        return this.each(function () {
            var JQself = $(this);
            var JQfather = JQself.parent();

            if (JQfather.css("position") != "relative") {
                var JQtemp = $('<div class="followParent32" style=" width:100%; height:100%; position:relative;"></div>');
                JQfather.children().appendTo(JQtemp);
                JQtemp.appendTo(JQfather);
            }
            JQself.css("position", "absolute");

            if (options.cutWidth || options.cutWidth == 0) {
                JQself.width(JQfather.width() - options.cutWidth);
            }
            if (options.cutHeight || options.cutHeight == 0) {
                JQself.height(JQfather.height() - options.cutHeight);
            }
            if (options.top || options.top == 0) {
                JQself.css("top", options.top);
            }
            if (options.bottom || options.bottom == 0) {
                JQself.css("top", JQfather.height() - JQself.height() - options.bottom);
            }
            if (options.left || options.left == 0) {
                JQself.css("left", options.left);
            }
            if (options.right || options.right == 0) {
                JQself.css("left", JQfather.width() - JQself.width() - options.right);
            }
            if (options.center) {
                JQself.css("left", (JQfather.width() - JQself.width()) / 2);
            }
            if (options.middle) {
                JQself.css("top", (JQfather.height() - JQself.height()) / 2);
            }
        });
    }
})(jQuery);

//1.2.0 支持计算子对象的边框和被白
//1.2.1 不再使用在IE不支持的outerWidth()和outerHeight()方法，但不计算子对象的边框和被白了
//1.2.2 添加了两个默认参数，left和top









$.fn.left32 = function (option) {
    if (option || option == 0) {
        return this.each(function () {
            $(this).css({ "left": option });
        });
    } else {
        var result = null;
        this.each(function () {
            result = $(this).css("left");
            result = parseInt(result);
            return false;
        });
        return result;
    }
}

$.fn.top32 = function (option) {
    if (option || option == 0) {
        return this.each(function () {
            $(this).css({ "top": option });
        });
    } else {
        var result = null;
        this.each(function () {
            result = $(this).css("top");
            result = parseInt(result);
            return false;
        });
        return result;
    }
}